<template>
	<div class="content">
		<div class="clear">
			<Form inline class="fl">
				<Input type="text" placeholder="提现编号" class="w200 m-r10" v-model="bianhao" />
				<Input type="text" placeholder="用户名" class="w200 m-r10" v-model="userId" />
				<Select placeholder="请选择提现状态" class="w200 m-r10" v-model="zhuangtai">
					<Option value="1">成功</Option>
					<Option value="2">失败</Option>
					<Option value="3">待审核</Option>
					<Option value="4">已审核</Option>
					<Option value="5">转账中</Option>
				</Select>
				<DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd HH:mm:ss" @on-change="getTime">
				</DatePicker>
				<Button type="primary" @click="query">查询</Button>
			</Form>
		</div>
		<fieldset>
			<legend>总钱包信息</legend>
			<div>
				<table>
					<tbody>
						<tr>
							<td>总钱包地址：
								<span class="blue">{{ qianbao.btcAddress == null ? '暂无' : qianbao.btcAddress }}</span>
							</td>
							<td class="left-200">USDT余额：
								<span class="blue">{{ qianbao.btc == null ? 0 : qianbao.btc }}</span>
							</td>
						</tr>

					</tbody>
				</table>
			</div>
		</fieldset>
		<fieldset>
			<legend>提币汇总</legend>
			<div>
				<table>
					<tbody>
						<tr>
							<td>累计USDT提币数量：
								<span class="blue">{{ huizong.btcNum == null ? 0 : huizong.btcNum }}</span>
							</td>
							<td class="left-300">累计USDT提币手续费：
								<span class="blue">{{ huizong.btcFee == null ? 0 : huizong.btcFee }}</span>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</fieldset>
		<Button class="daochu" type="primary" size="large" @click="exportData">
            <Icon type="ios-download-outline"></Icon> 导出</Button>
		<Table stripe :columns="columns1" :data="btcList" ref="table" v-show="btc"></Table>
		<Page :total="info" show-elevator :page-size="pageSize" show-total @on-change="changepage" v-show="fenye"></Page>
		<Page :total="info1" show-elevator :page-size="pageSize" show-total @on-change="changepage1" v-show="fenye1"></Page>
		<Page :total="info2" show-elevator :page-size="pageSize" show-total @on-change="changepage2" v-show="fenye2"></Page>
		<Page :total="info3" show-elevator :page-size="pageSize" show-total @on-change="changepage3" v-show="fenye3"></Page>

		<Modal v-model="modal1" title="审核" width='40%' @on-ok="shenhe">
			<Form :label-width="100">
				<FormItem label="审核状态">
					<Select placeholder="请选择审核状态" class="w200 m-r10" v-model="shenhezt">
						<Option value="4">审核通过</Option>
						<Option value="2">失败</Option>
					</Select>
				</FormItem>
				<FormItem label="审核备注">
					<Input type="textarea" placeholder="请输入审核备注" v-model="beizhu" />
				</FormItem>
			</Form>
		</Modal>
	</div>
</template>
<script>
	export default {
		data() {
			return {
				btc: true,
				eth: false,
				usdt: false,
				ebkc: false,
				fenye: true,
				fenye1: false,
				fenye2: false,
				fenye3: false,
				checkNum: '',
				qianbao: {}, // 钱包汇总
				huizong: {}, // 汇总
				btcList: [],
				ethList: [],
				usdtList: [],
				ebkcList: [],
				bianhao: '', // 编号
				bizhong: '1', // 币种
				userId: '', // ID
				zhuangtai: '', // 状态
				shenhezt: '', //  审核状态
				beizhu: '', // 备注
				id: '', // 审核提现记录id
				memberId: '', // 审核ID
				kind: '', // 审核对应表标识
				dataValue: [], // 时间段值
				startTime1: '',
				endTime1: '',
				modal1: false,
				// // 分页
				info: null, // 总条数
				info1: null, // 总条数
				info2: null, // 总条数
				info3: null, // 总条数
				page: 1, // 页数
				pageSize: 20, // 每页多少条
				columns1: [{
						title: '提现编号',
						key: 'transferId',
						width: 200,
						align: 'center',
						fixed: 'left'
					},
					{
						title: '个人ID',
						key: 'uuid',
						align: 'center',
						width: 150
					},
					{
						title: '提现数量',
						key: 'num',
						align: 'center',
						width: 150
					},
					{
						title: '手续费',
						key: 'appFee',
						align: 'center',
						width: 150
					},
					{
						title: '到账数量',
						key: 'actualNum',
						align: 'center',
						width: 150
					},
					{
						title: '接收钱包地址',
						width: 350,
						align: 'center',
						key: 'toAddress'
					},
					{
						title: '提现状态',
						key: 'status',
						align: 'center',
						width: 150,
						render: (h, params) => {
							if(this.btcList[params.index].status == 1) {
								return h('div', '成功')
							} else if(this.btcList[params.index].status == 2) {
								return h('div', '失败')
							} else if(this.btcList[params.index].status == 3) {
								return h('div', '待审核')
							} else if(this.btcList[params.index].status == 4) {
								return h('div', '已审核')
							} else if(this.btcList[params.index].status == 5) {
								return h('div', '转账中')
							}
						}
					},
					{
						title: '备注',
						key: 'remark',
						align: 'center',
						width: 200
					},
					{
						title: '提交时间',
						width: 150,
						align: 'center',
						key: 'createTime',
						sortable: true
					},
					{
						title: '操作',
						key: 'action',
						width: 200,
						fixed: 'right',
						align: 'center',
						render: (h, params) => {
							if(this.btcList[params.index].status == 3) {
								return h('div', [
									h(
										'Button', {
											props: {
												type: 'primary',
												size: 'small'
											},
											style: {
												marginRight: '5px'
											},
											on: {
												click: () => {
													this.show(this.btcList[params.index].id, this.btcList[params.index].memberId, 2)
												}
											}
										},
										'审核'
									)
								])
							} else {
								return h('div', [
									h(
										'Button', {
											props: {
												type: 'primary',
												size: 'small',
												disabled: true
											},
											style: {
												marginRight: '5px'
											},
										},
										'已审核'
									)
								])
							}
						}
					}

				]
			}
		},
		methods: {
			// // 审核
			show(id, memberId, kind) {
				this.modal1 = true
				this.id = id
				this.memberId = memberId
				this.kind = kind
			},

			shenhe() {
				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					id: this.id,
					memberId: this.memberId,
					kind: this.kind,
					status: this.shenhezt,
					remark: this.beizhu
				})
				this.axios.post('financial/withdrawalaudit', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.$Message.info(res.data.message)
						this.id = null,
							this.shenhezt = null,
							this.beizhu = null
						if(this.kind == 1) {
							this.getEList()
						} else if(this.kind == 2) {
							this.getBList()
						} else if(this.kind == 3) {
							this.getUList()
						} else if(this.kind == 4) {
							this.getCList()
						}
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message)
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message)
						localStorage.removeItem('mytoken')
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			exportData() {
				this.$refs.table.exportCsv({
					filename: 'BTC提现审核'
				})
				this.$refs.table1.exportCsv({
					filename: 'ETH提现审核'
				})
			},
			// // 处理时间段时间格式
			getTime(daterange) {
				this.dataValue = daterange
			},
			// 获取BTC数据
			getBList() {
				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					pn: this.page,
					pageSize: this.pageSize
				})
				this.axios.post('financial/btcwithdrawlist', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					//  console.log(res)
					if(res.data.code == 8008) {
						this.btcList = res.data.data.Btcresult
						this.info = res.data.data.Btcinteger
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message)
						localStorage.removeItem('mytoken')
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			// 获取eth数据
			getEList() {
				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					pn: this.page,
					pageSize: this.pageSize
				})
				this.axios.post('financial/ethwithdrawlist', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					//  console.log(res)
					if(res.data.code == 8008) {
						this.ethList = res.data.data.Ethresult
						this.info1 = res.data.data.Ethinteger
					}
				})
			},
			// 获取usdt数据
			getUList() {
				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					pn: this.page,
					pageSize: this.pageSize
				})
				this.axios.post('financial/usdtwithdrawlist', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					//  console.log(res)
					if(res.data.code == 8008) {
						this.usdtList = res.data.data.Usdtresult
						this.info2 = res.data.data.Usdtinteger
					}
				})
			},
			// 获取ebkc数据
			getCList() {
				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					pn: this.page,
					pageSize: this.pageSize
				})
				this.axios.post('financial/ebkcwithdrawlist', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					//  console.log(res)
					if(res.data.code == 8008) {
						this.ebkcList = res.data.data.Ebkctresult
						this.info3 = res.data.data.Ebkcinteger
					}
				})
			},
			// 获取提币汇总
			getHuizong() {
				let token = localStorage.getItem('mytoken')
				this.axios.get('financial/withdrawcollect', {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					// console.log(res)
					if(res.data.code == 8008) {
						this.huizong = res.data.data.withdrawVO
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message)
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message)
						localStorage.removeItem('mytoken')
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			// 获取钱包地址，币
			getQianbao() {
				let token = localStorage.getItem("mytoken");
				this.axios.get('financial/address/balance', {
					headers: {
						Authorization: "bearer " + token
					}
				}).then(res => {
					// console.log(res)
					if(res.data.code == 8008) {
						this.qianbao = res.data.data.balance
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message);
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem("mytoken");
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			// 查询
			query() {
				if(this.bizhong == 1) {
					this.btc = true
					this.eth = false
					this.usdt = false
					this.ebkc = false
					this.fenye = true
					this.fenye1 = false
					this.fenye2 = false
					this.fenye3 = false
					if(this.dataValue == undefined || this.dataValue[0] == '' || this.dataValue.length == 0 && this.userId == '' && this.zhuangtai == '' && this.bianhao == '') {
						this.getBList()
						return
					}

					let token = localStorage.getItem('mytoken')
					let params = this.qs.stringify({
						number: this.bianhao,
						uuid: this.userId,
						pageSize: this.pageSize,
						pn: this.page,
						status: this.zhuangtai,
						startTime: this.dataValue[0] == '' ? '2000-12-30 00:00:00' : this.dataValue[0],
						endTime: this.dataValue[1] == '' ? '2200-12-30 00:00:00' : this.dataValue[1]
					})
					this.axios
						.post('financial/btcwithdrawlist', params, {
							headers: {
								Authorization: 'bearer ' + token
							}
						})
						.then(res => {
							if(res.data.code == 8008) {
								this.btcList = res.data.data.Btcresult
								this.info = this.btcList.length
							} else if(res.data.code == 4004) {
								this.$Message.info(res.data.message)
							} else if(res.data.code == 5501) {
								this.$Message.info(res.data.message)
								localStorage.removeItem('mytoken')
								this.$router.push({
									name: 'login'
								})
							}
						})
				} else if(this.bizhong == 2) {
					this.btc = false
					this.eth = true
					this.usdt = false
					this.ebkc = false
					this.fenye = false
					this.fenye1 = true
					this.fenye2 = false
					this.fenye3 = false
					if((this.dataValue == undefined || this.dataValue[0] == '' || this.dataValue.length == 0) && this.userId == '' && this.zhuangtai == '' && this.bianhao == '') {
						this.getEList()
						return
					}

					let token = localStorage.getItem('mytoken')
					let params = this.qs.stringify({
						number: this.bianhao,
						uuid: this.userId,
						pageSize: this.pageSize,
						pn: this.page,
						status: this.zhuangtai,
						startTime: this.dataValue[0] == '' ? '2000-12-30 00:00:00' : this.dataValue[0],
						endTime: this.dataValue[1] == '' ? '2200-12-30 00:00:00' : this.dataValue[1]
					})
					this.axios
						.post('financial/ethwithdrawlist', params, {
							headers: {
								Authorization: 'bearer ' + token
							}
						})
						.then(res => {
							if(res.data.code == 8008) {
								this.ethList = res.data.data.Ethresult
								this.info1 = this.ethList.length
							} else if(res.data.code == 4004) {
								this.$Message.info(res.data.message)
							} else if(res.data.code == 5501) {
								this.$Message.info(res.data.message)
								localStorage.removeItem('mytoken')
								this.$router.push({
									name: 'login'
								})
							}
						})
				} else if(this.bizhong == 3) {
					this.btc = false
					this.eth = false
					this.usdt = true
					this.ebkc = false
					this.fenye = false
					this.fenye1 = false
					this.fenye2 = true
					this.fenye3 = false
					if(this.dataValue == undefined || this.dataValue[0] == '' || this.dataValue.length == 0 && this.userId == '' && this.zhuangtai == '' && this.bianhao == '') {
						this.getUList()
						return
					}

					let token = localStorage.getItem('mytoken')
					let params = this.qs.stringify({
						number: this.bianhao,
						uuid: this.userId,
						pageSize: this.pageSize,
						pn: this.page,
						status: this.zhuangtai,
						startTime: this.dataValue[0] == '' ? '2000-12-30 00:00:00' : this.dataValue[0],
						endTime: this.dataValue[1] == '' ? '2200-12-30 00:00:00' : this.dataValue[1]
					})
					this.axios
						.post('financial/usdtwithdrawlist', params, {
							headers: {
								Authorization: 'bearer ' + token
							}
						})
						.then(res => {
							if(res.data.code == 8008) {
								this.usdtList = res.data.data.Usdtresult
								this.info2 = this.usdtList.length
							} else if(res.data.code == 4004) {
								this.$Message.info(res.data.message)
							} else if(res.data.code == 5501) {
								this.$Message.info(res.data.message)
								localStorage.removeItem('mytoken')
								this.$router.push({
									name: 'login'
								})
							}
						})
				} else if(this.bizhong == 4) {
					this.btc = false
					this.eth = false
					this.usdt = false
					this.ebkc = true
					this.fenye = false
					this.fenye1 = false
					this.fenye2 = false
					this.fenye3 = true
					// console.log(this.dataValue)
					if(this.dataValue == undefined || this.dataValue[0] == '' || this.dataValue.length == 0 && this.userId == '' && this.zhuangtai == '' && this.bianhao == '') {
						this.getCList()
						return
					}

					let token = localStorage.getItem('mytoken')
					let params = this.qs.stringify({
						number: this.bianhao,
						uuid: this.userId,
						pageSize: this.pageSize,
						pn: this.page,
						status: this.zhuangtai,
						startTime: this.dataValue[0] == '' ? '2000-12-30 00:00:00' : this.dataValue[0],
						endTime: this.dataValue[1] == '' ? '2200-12-30 00:00:00' : this.dataValue[1]
					})
					this.axios
						.post('financial/ebkcwithdrawlist', params, {
							headers: {
								Authorization: 'bearer ' + token
							}
						})
						.then(res => {
							if(res.data.code == 8008) {
								this.ebkcList = res.data.data.Ebkctresult
								this.info3 = this.ebkcList.length
							} else if(res.data.code == 4004) {
								this.$Message.info(res.data.message)
							} else if(res.data.code == 5501) {
								this.$Message.info(res.data.message)
								localStorage.removeItem('mytoken')
								this.$router.push({
									name: 'login'
								})
							}
						})
				}
			},

			// 分页
			changepage(page) {
				this.page = page
				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					pn: page,
					pageSize: this.pageSize
				})
				// console.log(params)
				this.axios.post('financial/btcwithdrawlist', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.btcList = res.data.data.Btcresult
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message)
						localStorage.removeItem('mytoken')
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			// 分页
			changepage1(page) {
				this.page = page
				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					pn: page,
					pageSize: this.pageSize
				})
				// console.log(params)
				this.axios.post('financial/ethwithdrawlist', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.ethList = res.data.data.Ethresult
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message)
						localStorage.removeItem('mytoken')
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			// 分页
			changepage2(page) {
				this.page = page
				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					pn: page,
					pageSize: this.pageSize
				})
				// console.log(params)
				this.axios.post('financial/usdtwithdrawlist', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.usdtList = res.data.data.Usdtresult
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message)
						localStorage.removeItem('mytoken')
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			// 分页
			changepage3(page) {
				this.page = page
				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					pn: page,
					pageSize: this.pageSize
				})
				// console.log(params)
				this.axios.post('financial/ebkcwithdrawlist', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.ebkcList = res.data.data.Ebkctresult
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message)
						localStorage.removeItem('mytoken')
						this.$router.push({
							name: 'login'
						})
					}
				})
			}
		},
		created() {
			this.getBList()

			setTimeout(() => {
				this.getEList()
			}, 400)
			setTimeout(() => {
				this.getUList()
			}, 800)
			setTimeout(() => {
				this.getCList()
			}, 1200)
			this.getHuizong()
			this.getQianbao()
		},
		mounted() {
			this.$Message.config({
				top: 250
			})
		}
	}
</script>